var modbus = require('./modbus.js');

var deviceAddr = 1;
var device = modbus(
  { id: 'UART2' },
  { id: 'D13', polarity: 1 },
  deviceAddr
);

var events = require('events');
var event = new events();
var status = 0x01;
setInterval(function () {
  device.write('c1-8', status).then(function (data) {
    console.log('write c1 data ' + data);
  });
  /* read back */
}, 2000);

event.on('write', function () {
  device.read('c1').then(function (data) {
    console.log('read c1 data ' + data);
  });
})

// /* read single coil */
device.read('c1').then(function (data) {
  console.log('read single coil data ' + data);
})

// /* read multi coil */
device.read('c1-8').then(function (data) {
  console.log('read single coil data ' + data);
})

// /* read input register */
device.read('i1-8').then(function (data) {
  console.log('read single coil data ' + data);
})

// /* wtite single coil */
device.write('c5', status).then(function (data) {
  console.log('write c1 data ' + data);
});